<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<jsp:include page="../../include/top.jsp"/>
<div class="main_body">
    <div class="span9 page_message">
        <section id="contents">
            <ul class="tab-nav nav">
                <li><a href="${BasePath}/app/activity/list?${PublicParams}">活动列表<span class="arrow fa fa-sort-up"></span></a></li>
                <li class="current"><a href="">活动添加/修改<span class="arrow fa fa-sort-up"></span></a></li>
            </ul>
            <div class="tab-content">
                <div id="tab1" class="tab-pane in tab1">
                    <!-- 表单 -->
                    <form class="form-horizontal" id="myForm" name="myForm" action="${BasePath}/app/activity/save" method="post">
                        <input type="hidden" name="id" value="${obj.id }"/>

                        <div class="form-item cf toggle-orderFrom">
                            <label class="item-label">
                                <span class="need_flag">*</span>
                                标题：
                                <span class="check-tips"></span>
                            </label>

                            <div class="controls">
                                <input type="text" class="input-xlarge focused" name="title" id="title" value="${obj.title }">
                            </div>
                        </div>
                        <div class="form-item cf toggle-orderFrom">
                            <label class="item-label">
                                <span class="need_flag">*</span>
                                跳转链接：
                                <span class="check-tips"></span>
                            </label>

                            <div class="controls">
                                <input type="text" class="input-xlarge focused" name="link" id="link" value="${obj.link }">
                            </div>
                        </div>
                        <div class="form-item cf toggle-startDate">
                            <label class="item-label">
                                <span class="need_flag">*</span>
                                有效日期：
                                <span class="check-tips"></span>
                            </label>
                            <div class="controls">
                                <input type="text" class="Wdate" id="startDate" name="startDate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'#F{$dp.$D(\'endDate\')}',readOnly:'false'})"/>
                                至
                                <input type="text" class="Wdate" id="endDate" name="endDate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'startDate\')}',readOnly:'false'})"/>
                            </div>
                        </div>
                        <div class="form-item cf toggle-cover">
                            <label class="item-label">
                                封面图片
                                <span class="check-tips"></span>
                            </label>
                            <div class="controls">
                                <input type="hidden" name="image" value="${obj.image}" id="images"/>
                                <div class="upload-img-box">
                                    <c:if test="${obj!=null && obj.image!=''}">
                                        <div class="upload-pre-item2"><img width="180" height="100" src="${obj.image}"/>
                                            <input type="hidden" name="hideImages" value="${obj.image}"/>
                                            <input type="button" class="imageDelete btn btn-small" onclick="deleteImage(this)" value="删除"/>
                                        </div>
                                    </c:if>
                                </div>
                                <div class="uploadrow2" title="点击修改图片">
                                    <input type="file" name="file" id="upload_picture_cover"/>
                                    <input type="hidden" name="cover" id="cover_id_cover"/>
                                </div>
                                <script type="text/javascript">
                                    $(function () {
                                        /* 初始化上传插件 */
                                        $("#upload_picture_cover").uploadify({
                                            "height": 100,
                                            "swf": "${BasePath}/Public/static/uploadify/uploadify.swf",
                                            "fileObjName": "file",
                                            "buttonText": "上传图片",
                                            "uploader": "${BasePath}/base/image/upload;jsessionid=<%=session.getId()%>",
                                            "width": 180,
                                            'removeTimeout': 1,
                                            'fileTypeExts': '*.jpg; *.png; *.gif;',
                                            'onUploadSuccess': uploadPicturecover
                                        });
                                        function uploadPicturecover(file, data) {
                                            var data = $.parseJSON(data);
                                            var src = '';
                                            if (data.errno) {
                                                src = data.url || '' + data.path;
                                                $("#cover_id_cover").parent().parent().find('.upload-img-box').html('<div class="upload-pre-item2"><img width="180" height="100" src="' + src + '"/><input type="hidden" name="hideImages" value="' + data.uri + '"/><input type="button" class="imageDelete btn btn-small" onclick="deleteImage(this)" value="删除"/></div>');
                                                <%--$('.weixin-cover-pic').attr('src', "${BasePath}" + src);--%>
                                                $("#images").val(data.uri);
                                            } else {
                                                updateAlert(data.errdesc);
                                                setTimeout(function () {$('#top-alert').find('button').click();$(that).removeClass('disabled').prop('disabled', false);}, 1500);
                                            }
                                        }
                                    });

                                    function deleteImage(obj) {
                                        $(obj).parent().remove();
                                        var objs = $("input[name=hideImages]");
                                        var arr = [];
                                        for (i = 0; i < objs.length; i++) {
                                            arr.push($(objs[i]).val());
                                        }
                                        $("#images").val(arr.join(";"));
                                    }
                                </script>
                            </div>
                        </div>

                        <div class="form-item cf">
                            <button class="btn submit-btn" id="submit" onclick="checkForm()" type="button">确 定</button>
                        </div>
                    </form>
                </div>
            </div>
        </section>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        setByIdFormatDate("startDate", '${obj.startDate}');
        setByIdFormatDate("endDate", '${obj.endDate}');
    });
    function checkForm() {
        var title = $("#title").val();
        if (title.trim() == "") {
            layer.msg('标题不能为空!', {icon: 5});
            return false;
        }
        var link = $("#link").val();
        if (link.trim() == "") {
            layer.msg('链接不能为空!', {icon: 5});
            return false;
        }
        var startDate = $("#startDate").val();
        if (startDate.trim() == "") {
            layer.msg('开始时间不能为空!', {icon: 5});
            return false;
        }
        var endDate = $("#endDate").val();
        if (endDate.trim() == "") {
            layer.msg('结束时间不能为空!', {icon: 5});
            return false;
        }
        var image = document.getElementsByName("hideImages");
        if (image.length == 0) {
            layer.msg('图片不能为空!', {icon: 5});
            return false;
        }
        $('#myForm').ajaxSubmit(function (data) {
            if (data.errno == 1) {
                layer.msg(data.errdesc, {icon: 5});
            } else {
                layer.msg('操作成功！');
                window.location.href = "${BasePath}/app/activity/list?${PublicParams}";
            }
        });
    }
</script>
<jsp:include page="../../include/bottom.jsp"/>
